import { Navigate, createBrowserRouter } from "react-router-dom";
import All from "../views/All/All"
import Home from "../views/Home/Home";
import Reserve from "../views/Reserve/Reserve";
import Message from "../views/Message/Message";
import Login from "../views/Login/Login";
import My from "../views/My/My";
import Money from "../views/Money/Money";
import Select from "../views/Select/Select";
import Chat from "../views/Message/Chat";

const IsLogin = (props) => {
    let Com = props.children.type
    if (localStorage.getItem("accessToken") || localStorage.getItem("refreshToken") ) {
        return <Com></Com>
    } else {
        return <Navigate to="/login" ></Navigate>
    }
}
import Address from "../views/My/Address";
import AddAddress from "../views/My/AddAddress";
import Privacy from "../views/My/Privacy";
import Cart from "../views/Taxi/Cart"
import Vouchers from "../views/Taxi/Vouchers";
import Recharge from "../views/Money/Recharge";
import Manner from "../views/Money/Manner";
import Password from "../views/Money/Password";
import Pay from "../views/Taxi/Pay";
import Driver from "../views/Home/driver/Driver";
import Cancel from "../views/Taxi/Cancel";

const router = createBrowserRouter([
    //登录
    {
        path: "/login",
        element: <Login></Login>
    },
    {
        path: "/all",
        element: <IsLogin><All></All></IsLogin>,
        children: [
            //首页
            {
                path: "/all/home",
                element: <Home></Home>
            },
            //预定
            {
                path: "/all/reserve",
                element: <Reserve></Reserve>
            },
            //消息
            {
                path: "/all/message",
                element: <Message></Message>,
                children: [

                ]
            },
            //钱包
            {
                path: "/all/money",
                element: <Money></Money>
            },
            //我的
            {
                path: "/all/my",
                element: <My></My>,
            },
            {
                path: "/all",
                element: <Navigate to="/all/home"></Navigate>
            },
        ]
    },
    //搜索
    {
        path: "/select",
        element: <Select></Select>
    },
    // 通话页面
    {
        path: "/chat/:id",
        element: <Chat></Chat>
    },
    //选择车辆类型
    {
        path:"/cart",
        element:<Cart></Cart>
    },
    //选择优惠券
    {
        path:"/vouchers",
        element:<Vouchers></Vouchers>
    },
    //钱包充值页面
    {
        path:"/recharge",
        element:<Recharge></Recharge>
    },
    //充值方式
    {
        path:"/manner",
        element:<Manner></Manner>
    },
    //钱包密码充值
    {
        path:"/password",
        element:<Password></Password>
    },
    //打车支付方式
    {
        path:"/pay",
        element:<Pay></Pay>
    },
    //取消打车
    {
        path:"/cancel",
        element:<Cancel></Cancel>
    },
    {
        path: "/",
        element: <Navigate to="/all"></Navigate>
    },
    // 我的-地址信息
    {
        path: "/address",
        element: <Address />
    },
    // 我的-添加地址
    {
        path: "/addAddress",
        element: <AddAddress/>
    },
    {
        path: "/privacy",
        element: <Privacy/>
    },
    //司机到达页面
    {
        path: "/driver",
        element: <Driver/>
    }
])


export default router;